#ifndef _VOICEBROADAST_H_
#define _VOICEBROADAST_H_
// ······································//
// ··········Broadcast section···········//
// ······································//

void play_00(uint8_t num, uint8_t mode /*0表示单位数字播报一位，1表示单位数字播报两位*/)
{
    if (!mode)
    {
        if (num / 10 > 0)
        {
            if (num / 10 != 1) // 十位
            {
                myDFPlayer.playFolder(1, (num / 10) + 1);
                delay(broadcastgap + 170);
            }
            myDFPlayer.playFolder(1, 12); // 十
            delay(broadcastgap + 170);

            if (num / 10 != 0 && num % 10 != 0)
            {
                myDFPlayer.playFolder(1, (num % 10) + 1); // 个位
                delay(broadcastgap + 170);
            }
        }
        else
        {
            myDFPlayer.playFolder(1, (num % 10) + 1);
            delay(broadcastgap + 170);
        }
    }
    else
    {
        if (num / 10 > 0)
        {
            if (num / 10 != 1) // 十位
            {
                myDFPlayer.playFolder(1, (num / 10) + 1);
                delay(broadcastgap + 170);
            }

            myDFPlayer.playFolder(1, 12); // 十
            delay(broadcastgap + 170);

            if (num / 10 != 0 && num % 10 != 0)
            {
                myDFPlayer.playFolder(1, (num % 10) + 1); // 个位
                delay(broadcastgap + 170);
            }
        }
        else
        {
            myDFPlayer.playFolder(1, (num / 10) + 1);
            delay(broadcastgap + 170);
            myDFPlayer.playFolder(1, (num % 10) + 1);
            delay(broadcastgap + 170);
        }
    }
}

void day_broadcast()
{
    myDFPlayer.playFolder(1, 93); // 今天是
    delay(broadcastgap * 3);
    play_00(time_now.month, 0);
    myDFPlayer.playFolder(1, 91); // 月
    delay(broadcastgap);

    play_00(time_now.day, 0);
    myDFPlayer.playFolder(1, 90); // 月
    delay(broadcastgap);
}

void time_broadcast()
{
    myDFPlayer.playFolder(1, 59); // 现在是
    delay(broadcastgap * 3);

    play_00(time_now.hour, 0);
    myDFPlayer.playFolder(1, 13); // 点
    delay(broadcastgap);

    play_00(time_now.min, 1);
    myDFPlayer.playFolder(1, 11); // 分
    delay(broadcastgap);
}

void weather_unit(uint8_t code /*天气代码*/)
{

    switch (code)
    {
    case 0:
        myDFPlayer.playFolder(1, 21);
        break;
    case 1:
        myDFPlayer.playFolder(1, 21);
        break;
    case 2:
        myDFPlayer.playFolder(1, 21);
        break;
    case 3:
        myDFPlayer.playFolder(1, 21);
        break;
    case 4:
        myDFPlayer.playFolder(1, 49);
        break;
    case 5:
        myDFPlayer.playFolder(1, 71);
        break;
    case 6:
        myDFPlayer.playFolder(1, 71);
        break;
    case 7:
        myDFPlayer.playFolder(1, 70);
        break;
    case 8:
        myDFPlayer.playFolder(1, 70);
        break;
    case 9:
        myDFPlayer.playFolder(1, 18);
        break;
    case 10:
        myDFPlayer.playFolder(1, 31);
        break;
    case 11:
        myDFPlayer.playFolder(1, 56);
        break;
    case 12:
        myDFPlayer.playFolder(1, 77);
        break;
    case 13:
        myDFPlayer.playFolder(1, 42);
        break;
    case 14:
        myDFPlayer.playFolder(1, 22);
        break;
    case 15:
        myDFPlayer.playFolder(1, 40);
        break;
    case 16:
        myDFPlayer.playFolder(1, 30);
        break;
    case 17:
        myDFPlayer.playFolder(1, 57);
        break;
    case 18:
        myDFPlayer.playFolder(1, 68);
        break;
    case 19:
        myDFPlayer.playFolder(1, 23);
        break;
    case 20:
        myDFPlayer.playFolder(1, 53);
        break;
    case 21:
        myDFPlayer.playFolder(1, 47);
        break;
    case 22:
        myDFPlayer.playFolder(1, 43);
        break;
    case 23:
        myDFPlayer.playFolder(1, 26);
        break;
    case 24:
        myDFPlayer.playFolder(1, 41);
        break;
    case 25:
        myDFPlayer.playFolder(1, 44);
        break;
    case 26:
        myDFPlayer.playFolder(1, 39);
        break;
    case 27:
        myDFPlayer.playFolder(1, 38);
        break;
    case 28:
        myDFPlayer.playFolder(1, 58);
        break;
    case 29:
        myDFPlayer.playFolder(1, 66);
        break;
    case 30:
        myDFPlayer.playFolder(1, 14);
        break;
    case 31:
        myDFPlayer.playFolder(1, 19);
        break;
    case 32:
        myDFPlayer.playFolder(1, 16);
        break;
    case 33:
        myDFPlayer.playFolder(1, 27);
        break;
    case 34:
        myDFPlayer.playFolder(1, 25);
        break;
    case 35:;
        break;
    case 36:
        myDFPlayer.playFolder(1, 60);
        break;
    case 37:
        myDFPlayer.playFolder(1, 17);
        break;
    case 38:
        myDFPlayer.playFolder(1, 15);
        break;
    case 99:
        myDFPlayer.playFolder(1, 67);
        break;

    default:
        myDFPlayer.playFolder(1, 67);
        break;
    }
}
void ana_winddir(uint8_t code)
{
    switch (code)
    {
    case 0:
        myDFPlayer.playFolder(1, 82);
        break;
    case 1:
        myDFPlayer.playFolder(1, 80);
        break;
    case 2:
        myDFPlayer.playFolder(1, 87);
        break;
    case 3:
        myDFPlayer.playFolder(1, 81);
        break;
    case 4:
        myDFPlayer.playFolder(1, 83);
        break;
    case 5:
        myDFPlayer.playFolder(1, 86);
        break;
    case 6:
        myDFPlayer.playFolder(1, 84);
        break;
    case 7:
        myDFPlayer.playFolder(2, 85);
        break;
    }
}

void weather_broadcast(uint8_t day)
{

    //    code_day;
    //    code_night;
    //    high;
    //    low;
    //    wind_direction;
    //    wind_scale
    //    rain;
    switch (day)
    {
    case 0:
        myDFPlayer.playFolder(1, 69); // 今天天气
        break;
    case 1:
        myDFPlayer.playFolder(1, 88); // 明天天气
        break;

    case 2:
        myDFPlayer.playFolder(1, 89); // 后天天气
        break;

    default:
        break;
    }

    delay(broadcastgap * 4);         // wait to broadcast finish
    weather_unit(wea[day].code_day); // xxxx
    delay(broadcastgap * 5);

    myDFPlayer.playFolder(1, 64); // 最高温度
    delay(broadcastgap * 4);      // wait to broadcast finish
    play_00(wea[day].high, 0);
    myDFPlayer.playFolder(1, 51); // 摄氏度
    delay(broadcastgap * 3);

    myDFPlayer.playFolder(1, 63); // 最低温度
    delay(broadcastgap * 4);      // wait to broadcast finish
    play_00(wea[day].low, 0);
    myDFPlayer.playFolder(1, 51); // 摄氏度
    delay(broadcastgap * 3);

    myDFPlayer.playFolder(1, 34); // 风向
    delay(broadcastgap * 2);
    ana_winddir(wea[day].wind_direction);
    delay(broadcastgap * 2);

    myDFPlayer.playFolder(1, 33); // 风力
    delay(broadcastgap * 2);
    play_00(wea[day].wind_scale, 0);
    myDFPlayer.playFolder(1, 20); // 级
    delay(broadcastgap);

    myDFPlayer.playFolder(1, 65); // 降水概率
    delay(broadcastgap * 4);
    myDFPlayer.playFolder(1, 61); // 百分之
    delay(broadcastgap * 3);
    play_00(wea[day].rain, 0);
}

void weather_broadcast_oleddisplay(uint8_t day)
{

    //    code_day;
    //    code_night;
    //    high;
    //    low;
    //    wind_direction;
    //    wind_scale
    //    rain;
    switch (day)
    {
    case 0:
        myDFPlayer.playFolder(1, 69); // 今天天气
        break;
    case 1:
        myDFPlayer.playFolder(1, 88); // 明天天气
        break;

    case 2:
        myDFPlayer.playFolder(1, 89); // 后天天气
        break;

    default:
        break;
    }
    unsigned int broadcastgap = 200; // 由于OLED的存在会导致一定延时因此调低gap
    int pos = 0;//存储像素位置达到滚动效果
    delay_print_weather(broadcastgap * 4, &pos); // wait to broadcast finish
    weather_unit(wea[day].code_day);             // xxxx
    delay_print_weather(broadcastgap * 5, &pos);

    myDFPlayer.playFolder(1, 64);                // 最高温度
    delay_print_weather(broadcastgap * 4, &pos); // wait to broadcast finish
    play_00(wea[day].high, 0);
    myDFPlayer.playFolder(1, 51); // 摄氏度
    delay_print_weather(broadcastgap * 3, &pos);

    myDFPlayer.playFolder(1, 63);                // 最低温度
    delay_print_weather(broadcastgap * 4, &pos); // wait to broadcast finish
    play_00(wea[day].low, 0);
    myDFPlayer.playFolder(1, 51); // 摄氏度
    delay_print_weather(broadcastgap * 3, &pos);

    myDFPlayer.playFolder(1, 34); // 风向
    delay_print_weather(broadcastgap * 2, &pos);
    ana_winddir(wea[day].wind_direction);
    delay_print_weather(broadcastgap * 2, &pos);

    myDFPlayer.playFolder(1, 33); // 风力
    delay_print_weather(broadcastgap * 2, &pos);
    play_00(wea[day].wind_scale, 0);
    myDFPlayer.playFolder(1, 20); // 级
    delay_print_weather(broadcastgap, &pos);

    myDFPlayer.playFolder(1, 65); // 降水概率
    delay_print_weather(broadcastgap * 4, &pos);
    myDFPlayer.playFolder(1, 61); // 百分之
    delay_print_weather(broadcastgap * 3, &pos);
    play_00(wea[day].rain, 0);
delay_print_weather(broadcastgap * 3, &pos);//delay to wait oled play finished

}

#endif